<template>
	<om-addpage style="padding-top: 35px;" menuName="费用报销" @formSubmit='getFormValue'
	 :showHistoryBtn="true" >
		<om-autoform ref="autoform" :initConfigData="configData" :initValue="initValue"></om-autoform>
		<om-sub title="工作经历" subTitle="请从最近的工作经历填起,应届毕业生可不填">
			<uni-list v-for="(item,index) in eduList" :key="index">
				<uni-list-item :showArrow="true" @click="openWork(index)">
					<view>{{item.school}}</view>
					<view class="text-gray text-sm padding-bottom-xs padding-top-xs">{{item.major}}</view>
					<view class="text-gray text-sm">{{item.startdate+' 至 '+item.enddate}}</view>
				</uni-list-item>
			</uni-list>
			<view class="tui-flex align-center justify-center padding-top">
				<text class="lg text-green cuIcon-add" @click="openWork()">增加工作经历</text>
			</view>
		</om-sub>
	</om-addpage>
</template>

<script>
	import autoform from '@/static/json/autoform.json'
	import {sumF} from '@/static/js/common.js'
	import {formValidation} from '@/static/js/formUtil.js'
	
	// import Vue from 'vue'
	// import uploader from 'vue-simple-uploader'
	
	// Vue.use(uploader)
	
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return {
				formdata: {},
				configData: autoform,
				subConfigData:[{}],
				initValue:{},
				userCacheKey:"test-form-user-cache",
				eduCacheKey:"test-form-edu-cache",
				eduList:[],
			}
		},
		watch:{
			formdata: {
				handler(newValue, oldValue) {
					this.changeValue()
				},
				deep:true
			}
		},
		methods: {
			
			handleMessage(e){
			},
			
			changeValue(){
				var income = sumF([this.formdata.salary1,this.formdata.salary2])
				this.$refs.autoform.formdata.income = income
			},
			getFormValue(){
				var checkRes = formValidation(this.$refs.autoform.configData, this.formdata)
				if(checkRes){
					this.om.toast(checkRes)
				}else{
					this.om.toast(JSON.stringify(this.formdata))
				}
			},
			//日期选择之后的验证
			dateVerifyfunc(){
				this.om.toast("验证通过")
				this.$refs.autoform.formdata.posName = "总经理" + this._.random(10)
				this.$refs.autoform.dataMap.info.username.prompt = this._.random(10)
				return true
			},
			openWork(index){
				var url = 'data-info?cachename=' + this.eduCacheKey
				if (index != null && index != undefined) {
					url += '&index=' + index
				}
				uni.navigateTo({
					url: url
				});
			},
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				uni.getStorage({
					key: _that.userCacheKey,
					success: function(res) {
						if(res.data) {
							let d = res.data
							_that.$refs.autoform.formdata.keyUserId = d.id
							_that.$refs.autoform.formdata.keyUserName = d.username
							_that.$refs.autoform.formdata.salaryPosName = d.salaryPosName
							uni.removeStorage({
								key: _that.userCacheKey
							});
						}
					}
				});
				uni.getStorage({
					key: _that.eduCacheKey,
					success: function(res) {
						_that.eduList = res.data;
						if (_that.eduList && _that.eduList.length) {
							_that.$refs.autoform.formdata.eduStr = JSON.stringify(_that.eduList)
						}else{
							_that.$refs.autoform.formdata.eduStr = ""
						}
					}
				});
			}
		}
	}
</script>

<style>
  .uploader-example {
     /* width: 880px; */
     padding: 15px;
     margin: 40px auto 0;
     font-size: 12px;
     /* box-shadow: 0 0 10px rgba(0, 0, 0, .4); */
   }
   .uploader-example .uploader-btn {
     margin-right: 4px;
   }
   .uploader-example .uploader-list {
		width: 100%;
		max-height: 440px;
		overflow: auto;
		/* overflow-x: hidden; */
		overflow-y: auto;
   }
</style>
